//
//  FMManageObject.m
//  ZAPlayer
//
//  Created by 邹奥 on 16/4/28.
//  Copyright © 2016年 zouao. All rights reserved.
//

#import "FMManageObject.h"

@implementation FMManageObject

+ (FMManageObject *)standerDefault
{
    static dispatch_once_t onceToken;
    static FMManageObject *manager = nil;
    dispatch_once(&onceToken, ^{
        manager = [[self alloc]init];
    });
    return manager;
}

- (id)init
{
    self = [super init];
    if (self) {
         _db = [[FMDatabase databaseWithPath:[self getFilePath]] retain];
    }
    return self;
}

- (NSString *)getFilePath
{
     NSString *filePath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)lastObject];
     return [filePath stringByAppendingPathComponent:@"data.db"];
}

#pragma mark - 封装
#pragma mark - 歌曲下载
//自定义文件-创建
- (BOOL)createMainTable:(NSString *)table byDB:(FMDatabase *)db//primary key
{
    //id,文件名
    return [db executeUpdate:[NSString stringWithFormat:@"create table %@(fileID text primary key ,fileName text,id text,url text,size text,type text)",table]];
}
//歌曲下载-查询
- (NSArray *)onSelectCustomMusicFileCount
{
    NSString *sql = [NSString stringWithFormat:@"select * from Main_table"];
    
    if (![_db open]) {
        NSLog(@"数据库没有打开!");
        return nil;
    }
    
    [_db setShouldCacheStatements:YES];
    
    if (![_db tableExists:@"Main_table"]) {
        if (![self createMainTable:@"Main_table" byDB:_db]) {
            NSLog(@"表单不存在!");
            return nil;
        }
    }
    
    NSMutableArray *data = [[NSMutableArray alloc]init];
    FMResultSet *result = [_db executeQuery:sql];
    while ([result next]) {
        NSString *idStr = [result stringForColumn:@"id"];
        NSString *fileName = [result stringForColumn:@"fileName"];
        NSString *fileID = [result stringForColumn:@"fileID"];
        NSString *url = [result stringForColumn:@"url"];
        NSString *size = [result stringForColumn:@"size"];
        NSString *type = [result stringForColumn:@"type"];
        NSDictionary *dic = [[NSDictionary alloc]initWithObjectsAndKeys:idStr,@"id",fileName,@"fileName",fileID,@"fileID",url,@"url",size,@"size",type,@"type", nil];
        [data addObject:dic];
    }
    
    if (![_db close]) {
        NSLog(@"数据库没有关闭!");
        return nil;
    }
    
    return data;
}

//自定义文件-根据文件名查询数据库是否存在
- (NSArray *)SelectTableWithFileID:(NSString *)fileName
{
    NSString *sql = [NSString stringWithFormat:@"select * from Main_table where fileID='%@'",fileName];
    if (![_db open]) {
        NSLog(@"数据库没有打开!");
        return nil;
    }
    
    [_db setShouldCacheStatements:YES];
    
    if (![_db tableExists:@"Main_table"]) {
        if (![self createMainTable:@"Main_table" byDB:_db]) {
            NSLog(@"表单不存在!");
            return nil;
        }
    }
    
    NSMutableArray *data = [[NSMutableArray alloc]init];
    FMResultSet *result = [_db executeQuery:sql];
    while ([result next]) {
        NSString *idStr = [result stringForColumn:@"id"];
        NSString *fileName = [result stringForColumn:@"fileName"];
        NSString *fileID = [result stringForColumn:@"fileID"];
        NSString *url = [result stringForColumn:@"url"];
        NSString *size = [result stringForColumn:@"size"];
        NSString *type = [result stringForColumn:@"type"];
        NSDictionary *dic = [[NSDictionary alloc]initWithObjectsAndKeys:idStr,@"id",fileName,@"fileName",fileID,@"fileID",url,@"url",size,@"size",type,@"type", nil];
        [data addObject:dic];
    }
    
    if (![_db close]) {
        NSLog(@"数据库没有关闭!");
        return nil;
    }
    
    return data;
}

//自定义文件-插入文件数据
- (BOOL)insertTableWithId:(NSString *)idStr withFileName:(NSString *)fileName withFileID:(NSString *)fileID withUrl:(NSString *)url withSize:(NSString *)size withType:(NSString *)type
{
    NSString *sql = [NSString stringWithFormat:@"insert into Main_table(id,fileName,fileID,url,size,type) values('%@','%@','%@','%@','%@','%@')",idStr,fileName,fileID,url,size,type];

    if (![_db open]) {
        NSLog(@"数据库没有打开!");
        return NO;
    }
    
    [_db setShouldCacheStatements:YES];
    
    if (![_db tableExists:@"Main_table"]) {
        if (![self createMainTable:@"Main_table" byDB:_db]) {
            NSLog(@"表单不存在!");
            return NO;
        }
    }
    
    BOOL isUpdate = [_db executeUpdate:sql];
    
    if (![_db close]) {
        NSLog(@"数据库没有关闭!");
        return NO;
    }
    
    return isUpdate;
}

//自定义文件-删除文件数据
- (BOOL)deleteCunstomFileID:(NSString *)CateID
{
    NSString *sql = [NSString stringWithFormat:@"delete from Main_table where fileID='%@'",CateID];
    if (![_db open]) {
        NSLog(@"数据库没有打开!");
        return NO;
    }
    
    [_db setShouldCacheStatements:YES];
    
    if (![_db tableExists:@"Main_table"]) {
        if (![self createMainTable:@"Main_table" byDB:_db]) {
            NSLog(@"表单不存在!");
            return NO;
        }
    }
    
    BOOL isUpdate = [_db executeUpdate:sql];
    
    if (![_db close]) {
        NSLog(@"数据库没有关闭!");
        return NO;
    }
    
    return isUpdate;
}

#pragma mark - 搜索历史
#define SEARCH_HISTORY (@"SearchHistory_table")
- (BOOL)createSearchHistoryTable:(NSString *)table byDB:(FMDatabase *)db//primary key
{
    //id,文件名
    return [db executeUpdate:[NSString stringWithFormat:@"create table %@(id text primary key,name text ,content text)",table]];
}

- (NSArray *)onSelectSearchHistoryCount
{
    NSString *sql = [NSString stringWithFormat:@"select * from '%@'",SEARCH_HISTORY];
    
    if (![_db open]) {
        NSLog(@"数据库没有打开!");
        return nil;
    }
    
    [_db setShouldCacheStatements:YES];
    
    if (![_db tableExists:SEARCH_HISTORY]) {
        if (![self createSearchHistoryTable:SEARCH_HISTORY byDB:_db]) {
            NSLog(@"表单不存在!");
            return nil;
        }
    }
    
    NSMutableArray *data = [[NSMutableArray alloc]init];
    FMResultSet *result = [_db executeQuery:sql];
    while ([result next]) {
        NSString *idStr = [result stringForColumn:@"id"];
        NSString *name = [result stringForColumn:@"name"];
        NSString *content = [result stringForColumn:@"content"];
        NSDictionary *dic = [[NSDictionary alloc]initWithObjectsAndKeys:idStr,@"id",name,@"name",content,@"content", nil];
        [data addObject:dic];
    }
    
    if (![_db close]) {
        NSLog(@"数据库没有关闭!");
        return nil;
    }
    
    return data;

}
//搜索历史-登录后根据帐号名查询数据库是否存在
- (NSArray *)SelectTableBySearchHistoryWithContent:(NSString *)Content withName:(NSString *)name
{
    NSString *sql;
    if (Content.length > 0) {
        if (name.length > 0) {
            sql = [NSString stringWithFormat:@"select * from '%@' where content='%@' and name='%@'",SEARCH_HISTORY,Content,name];
        } else {
            sql = [NSString stringWithFormat:@"select * from '%@' where content='%@'",SEARCH_HISTORY,Content];
        }
    } else {
        if (name.length > 0) {
            sql = [NSString stringWithFormat:@"select * from '%@' where name='%@'",SEARCH_HISTORY,name];
        } else {
            return @[];
        }
    }
    
    
    if (![_db open]) {
        NSLog(@"数据库没有打开!");
        return nil;
    }
    
    [_db setShouldCacheStatements:YES];
    
    if (![_db tableExists:SEARCH_HISTORY]) {
        if (![self createSearchHistoryTable:SEARCH_HISTORY byDB:_db]) {
            NSLog(@"表单不存在!");
            return nil;
        }
    }
    
    NSMutableArray *data = [[NSMutableArray alloc]init];
    FMResultSet *result = [_db executeQuery:sql];
    while ([result next]) {
        NSString *idStr = [result stringForColumn:@"id"];
        NSString *name = [result stringForColumn:@"name"];
        NSString *content = [result stringForColumn:@"content"];
        NSDictionary *dic = [[NSDictionary alloc]initWithObjectsAndKeys:idStr,@"id",name,@"name",content,@"content", nil];
        [data addObject:dic];
    }
    
    if (![_db close]) {
        NSLog(@"数据库没有关闭!");
        return nil;
    }
    
    return data;
}
//搜索历史-插入文件数据
- (BOOL)insertTableBySearchHistoryWithId:(NSString *)idStr withName:(NSString *)name withContent:(NSString *)content
{
    NSString *sql = [NSString stringWithFormat:@"insert into '%@'(id,name,content) values('%@','%@','%@')",SEARCH_HISTORY,idStr,name,content];
    
    if (![_db open]) {
        NSLog(@"数据库没有打开!");
        return NO;
    }
    
    [_db setShouldCacheStatements:YES];
    
    if (![_db tableExists:SEARCH_HISTORY]) {
        if (![self createSearchHistoryTable:SEARCH_HISTORY byDB:_db]) {
            NSLog(@"表单不存在!");
            return NO;
        }
    }
    
    BOOL isUpdate = [_db executeUpdate:sql];
    
    if (![_db close]) {
        NSLog(@"数据库没有关闭!");
        return NO;
    }
    
    return isUpdate;

}
//搜索历史-删除文件数据
- (BOOL)deleteBySearchHistoryFile:(NSString *)name
{
    NSString *sql = [NSString stringWithFormat:@"delete from '%@' where name='%@'",SEARCH_HISTORY,name];
    if (![_db open]) {
        NSLog(@"数据库没有打开!");
        return NO;
    }
    
    [_db setShouldCacheStatements:YES];
    
    if (![_db tableExists:SEARCH_HISTORY]) {
        if (![self createSearchHistoryTable:SEARCH_HISTORY byDB:_db]) {
            NSLog(@"表单不存在!");
            return NO;
        }
    }
    
    BOOL isUpdate = [_db executeUpdate:sql];
    
    if (![_db close]) {
        NSLog(@"数据库没有关闭!");
        return NO;
    }
    
    return isUpdate;
}

#pragma mark - 本地亲子秀
#define LOCAL_PARENT_CHILD_SHOW (@"LocalParentChildShow_table")
- (BOOL)createLocalParentChildShowTable:(NSString *)table byDB:(FMDatabase *)db//primary key
{
    //id,标题、发帖人ID、musicid、 感受，类型，图片、日期、mp3，发帖人头像、发帖人昵称、music大小
    return [db executeUpdate:[NSString stringWithFormat:@"create table %@(id text primary key,title text ,userId text,musicId text,content text,type text,picture text,date text,mp3 text,userPic text,userNick text,size text)",table]];
}

- (NSArray *)onSelectLocalParentChildShowCount
{
    NSString *sql = [NSString stringWithFormat:@"select * from '%@'",LOCAL_PARENT_CHILD_SHOW];
    
    if (![_db open]) {
        NSLog(@"数据库没有打开!");
        return nil;
    }
    
    [_db setShouldCacheStatements:YES];
    
    if (![_db tableExists:LOCAL_PARENT_CHILD_SHOW]) {
        if (![self createLocalParentChildShowTable:LOCAL_PARENT_CHILD_SHOW byDB:_db]) {
            NSLog(@"表单不存在!");
            return nil;
        }
    }
    
    NSMutableArray *data = [[NSMutableArray alloc]init];
    FMResultSet *result = [_db executeQuery:sql];
    while ([result next]) {
        NSString *idStr = [result stringForColumn:@"id"];
        NSString *name = [result stringForColumn:@"title"];
        NSString *userId = [result stringForColumn:@"userId"];
        NSString *musicId = [result stringForColumn:@"musicId"];
        NSString *address = [result stringForColumn:@"content"];
        NSString *type = [result stringForColumn:@"type"];
        NSString *picture = [result stringForColumn:@"picture"];
        NSString *date = [result stringForColumn:@"date"];
        NSString *mp3 = [result stringForColumn:@"mp3"];
        NSString *userPic = [result stringForColumn:@"userPic"];
        NSString *userNick = [result stringForColumn:@"userNick"];
        NSString *size = [result stringForColumn:@"size"];
        NSDictionary *dic = [[NSDictionary alloc]initWithObjectsAndKeys:idStr,@"id",name,@"title",userId,@"userId",musicId,@"musicId",address,@"content",type,@"type",picture,@"picture",date,@"date",mp3,@"mp3",userPic,@"userPic",userNick,@"userNick",size,@"size", nil];
        [data addObject:dic];
    }
    
    if (![_db close]) {
        NSLog(@"数据库没有关闭!");
        return nil;
    }
    
    return data;
    
}
//本地亲子秀-根据UserId获取本地
- (NSArray *)SelectTableByLocalParentChildShowWithUserId:(NSString *)date withMusicId:(NSString *)musicId
{
    NSString *sql = [NSString stringWithFormat:@"select * from '%@' where userId='%@' and musicId='%@'",LOCAL_PARENT_CHILD_SHOW,date,musicId];
    if (![_db open]) {
        NSLog(@"数据库没有打开!");
        return nil;
    }
    
    [_db setShouldCacheStatements:YES];
    
    if (![_db tableExists:LOCAL_PARENT_CHILD_SHOW]) {
        if (![self createLocalParentChildShowTable:LOCAL_PARENT_CHILD_SHOW byDB:_db]) {
            NSLog(@"表单不存在!");
            return nil;
        }
    }
    
    NSMutableArray *data = [[NSMutableArray alloc]init];
    FMResultSet *result = [_db executeQuery:sql];
    while ([result next]) {
        NSString *idStr = [result stringForColumn:@"id"];
        NSString *name = [result stringForColumn:@"title"];
        NSString *userId = [result stringForColumn:@"userId"];
        NSString *musicId = [result stringForColumn:@"musicId"];
        NSString *address = [result stringForColumn:@"content"];
        NSString *type = [result stringForColumn:@"type"];
        NSString *picture = [result stringForColumn:@"picture"];
        NSString *date = [result stringForColumn:@"date"];
        NSString *mp3 = [result stringForColumn:@"mp3"];
        NSString *userPic = [result stringForColumn:@"userPic"];
        NSString *userNick = [result stringForColumn:@"userNick"];
        NSString *size = [result stringForColumn:@"size"];
        NSDictionary *dic = [[NSDictionary alloc]initWithObjectsAndKeys:idStr,@"id",name,@"title",userId,@"userId",musicId,@"musicId",address,@"content",type,@"type",picture,@"picture",date,@"date",mp3,@"mp3",userPic,@"userPic",userNick,@"userNick",size,@"size", nil];
        [data addObject:dic];

    }
    
    if (![_db close]) {
        NSLog(@"数据库没有关闭!");
        return nil;
    }
    
    return data;
}
//本地亲子秀-插入文件数据
- (BOOL)insertTableByLocalParentChildShowWithId:(NSString *)idStr withTitle:(NSString *)title withUserId:(NSString *)userId withMusicId:(NSString *)musicID withContent:(NSString *)content withType:(NSString *)type withPicture:(NSString *)picture withDate:(NSString *)date withMp3:(NSString *)mp3 withUserPic:(NSString *)userPic withUserNick:(NSString *)nick withSize:(NSString *)size
{
    NSString *sql = [NSString stringWithFormat:@"insert into '%@'(id,title,userId,musicId,content,type,picture,date,mp3,userPic,userNick,size) values('%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@')",LOCAL_PARENT_CHILD_SHOW,idStr,title,userId,musicID,content,type,picture,date,mp3,userPic,nick,size];
    
    if (![_db open]) {
        NSLog(@"数据库没有打开!");
        return NO;
    }
    
    [_db setShouldCacheStatements:YES];
    
    if (![_db tableExists:LOCAL_PARENT_CHILD_SHOW]) {
        if (![self createLocalParentChildShowTable:LOCAL_PARENT_CHILD_SHOW byDB:_db]) {
            NSLog(@"表单不存在!");
            return NO;
        }
    }
    
    BOOL isUpdate = [_db executeUpdate:sql];
    
    if (![_db close]) {
        NSLog(@"数据库没有关闭!");
        return NO;
    }
    
    return isUpdate;
    
}
//本地亲子秀-删除文件数据
- (BOOL)deleteByLocalParentChildShowFilID:(NSString *)date
{
    NSString *sql = [NSString stringWithFormat:@"delete from '%@' where id='%@'",LOCAL_PARENT_CHILD_SHOW,date];
    if (![_db open]) {
        NSLog(@"数据库没有打开!");
        return NO;
    }
    
    [_db setShouldCacheStatements:YES];
    
    if (![_db tableExists:LOCAL_PARENT_CHILD_SHOW]) {
        if (![self createLocalParentChildShowTable:LOCAL_PARENT_CHILD_SHOW byDB:_db]) {
            NSLog(@"表单不存在!");
            return NO;
        }
    }
    
    BOOL isUpdate = [_db executeUpdate:sql];
    
    if (![_db close]) {
        NSLog(@"数据库没有关闭!");
        return NO;
    }
    
    return isUpdate;
}
#pragma mark - 播放历史
#define ONSHOW_PLAY_HISTORY (@"OnShowPlayHistory_table")
- (BOOL)createOnShowPlayHistoryTable:(NSString *)table byDB:(FMDatabase *)db//primary key
{
    //id,文件名，地址，日期
    return [db executeUpdate:[NSString stringWithFormat:@"create table %@(fileID text primary key ,fileName text,id text,url text,size text,type text)",table]];
}

- (NSArray *)onSelectPlayHistoryCount
{
    NSString *sql = [NSString stringWithFormat:@"select * from '%@'",ONSHOW_PLAY_HISTORY];
    
    if (![_db open]) {
        NSLog(@"数据库没有打开!");
        return nil;
    }
    
    [_db setShouldCacheStatements:YES];
    
    if (![_db tableExists:ONSHOW_PLAY_HISTORY]) {
        if (![self createOnShowPlayHistoryTable:ONSHOW_PLAY_HISTORY byDB:_db]) {
            NSLog(@"表单不存在!");
            return nil;
        }
    }
    
    NSMutableArray *data = [[NSMutableArray alloc]init];
    FMResultSet *result = [_db executeQuery:sql];
    while ([result next]) {
        NSString *idStr = [result stringForColumn:@"id"];
        NSString *name = [result stringForColumn:@"name"];
        NSString *address = [result stringForColumn:@"address"];
        NSString *date = [result stringForColumn:@"date"];
        NSDictionary *dic = [[NSDictionary alloc]initWithObjectsAndKeys:idStr,@"id",name,@"name",address,@"address",date,@"date", nil];
        [data addObject:dic];
    }
    
    if (![_db close]) {
        NSLog(@"数据库没有关闭!");
        return nil;
    }
    
    return data;
    
}
//本地亲子秀-根据日期获取本地
- (NSArray *)SelectTableByPlayHistoryWithContent:(NSString *)name
{
    NSString *sql = [NSString stringWithFormat:@"select * from '%@' where date='%@'",ONSHOW_PLAY_HISTORY,name];
    if (![_db open]) {
        NSLog(@"数据库没有打开!");
        return nil;
    }
    
    [_db setShouldCacheStatements:YES];
    
    if (![_db tableExists:ONSHOW_PLAY_HISTORY]) {
        if (![self createOnShowPlayHistoryTable:ONSHOW_PLAY_HISTORY byDB:_db]) {
            NSLog(@"表单不存在!");
            return nil;
        }
    }
    
    NSMutableArray *data = [[NSMutableArray alloc]init];
    FMResultSet *result = [_db executeQuery:sql];
    while ([result next]) {
        NSString *idStr = [result stringForColumn:@"id"];
        NSString *fileName = [result stringForColumn:@"fileName"];
        NSString *fileID = [result stringForColumn:@"fileID"];
        NSString *url = [result stringForColumn:@"url"];
        NSString *size = [result stringForColumn:@"size"];
        NSString *type = [result stringForColumn:@"type"];
        NSDictionary *dic = [[NSDictionary alloc]initWithObjectsAndKeys:idStr,@"id",fileName,@"fileName",fileID,@"fileID",url,@"url",size,@"size",type,@"type", nil];
        [data addObject:dic];
    }
    
    if (![_db close]) {
        NSLog(@"数据库没有关闭!");
        return nil;
    }
    
    return data;
}
//本地亲子秀-插入文件数据

-(BOOL)insertOnShowPlayHistoryTableWithId:(NSString *)idStr withFileName:(NSString *)fileName withFileID:(NSString *)fileID withUrl:(NSString *)url withSize:(NSString *)size withType:(NSString *)type
{
    NSString *sql = [NSString stringWithFormat:@"insert into '%@'(id,fileName,fileID,url,size,type) values('%@','%@','%@','%@','%@','%@')",ONSHOW_PLAY_HISTORY,idStr,fileName,fileID,url,size,type];
    
    if (![_db open]) {
        NSLog(@"数据库没有打开!");
        return NO;
    }
    
    [_db setShouldCacheStatements:YES];
    
    if (![_db tableExists:ONSHOW_PLAY_HISTORY]) {
        if (![self createOnShowPlayHistoryTable:ONSHOW_PLAY_HISTORY byDB:_db]) {
            NSLog(@"表单不存在!");
            return NO;
        }
    }
    
    BOOL isUpdate = [_db executeUpdate:sql];
    
    if (![_db close]) {
        NSLog(@"数据库没有关闭!");
        return NO;
    }
    
    return isUpdate;
}
//本地亲子秀-删除文件数据
- (BOOL)deleteByplayHistoryFile:(NSString *)name
{
    NSString *sql = [NSString stringWithFormat:@"delete from '%@' where date='%@'",ONSHOW_PLAY_HISTORY,name];
    if (![_db open]) {
        NSLog(@"数据库没有打开!");
        return NO;
    }
    
    [_db setShouldCacheStatements:YES];
    
    if (![_db tableExists:ONSHOW_PLAY_HISTORY]) {
        if (![self createOnShowPlayHistoryTable:ONSHOW_PLAY_HISTORY byDB:_db]) {
            NSLog(@"表单不存在!");
            return NO;
        }
    }
    
    BOOL isUpdate = [_db executeUpdate:sql];
    
    if (![_db close]) {
        NSLog(@"数据库没有关闭!");
        return NO;
    }
    
    return isUpdate;
}

#pragma mark - 点赞
#define PRAISE_HISTORY (@"Praise_table")
- (BOOL)createOnShowPraiseTable:(NSString *)table byDB:(FMDatabase *)db//primary key
{
    //id,文件名，地址，日期
    return [db executeUpdate:[NSString stringWithFormat:@"create table %@(ID text primary key ,praise text)",table]];
}
//点赞
-(NSArray*)onSelectPraiseCount
{
    NSString *sql = [NSString stringWithFormat:@"select * from '%@'",PRAISE_HISTORY];
    
    if (![_db open]) {
        NSLog(@"数据库没有打开!");
        return nil;
    }
    
    [_db setShouldCacheStatements:YES];
    
    if (![_db tableExists:PRAISE_HISTORY]) {
        if (![self createOnShowPraiseTable:PRAISE_HISTORY byDB:_db]) {
            NSLog(@"表单不存在!");
            return nil;
        }
    }
    
    NSMutableArray *data = [[NSMutableArray alloc]init];
    FMResultSet *result = [_db executeQuery:sql];
    while ([result next]) {
        NSString *IDStr = [result stringForColumn:@"ID"];
        NSString *praise = [result stringForColumn:@"praise"];
        NSDictionary *dic = [[NSDictionary alloc]initWithObjectsAndKeys:IDStr,@"ID",praise,@"praise", nil];
        [data addObject:dic];
    }
    
    if (![_db close]) {
        NSLog(@"数据库没有关闭!");
        return nil;
    }
    
    return data;

}
- (NSArray *)SelectTableByPraiseWithContentID:(NSString *)name
{
    NSString *sql = [NSString stringWithFormat:@"select * from '%@' where ID='%@'",PRAISE_HISTORY,name];
    if (![_db open]) {
        NSLog(@"数据库没有打开!");
        return nil;
    }
    
    [_db setShouldCacheStatements:YES];
    
    if (![_db tableExists:PRAISE_HISTORY]) {
        if (![self createOnShowPraiseTable:PRAISE_HISTORY byDB:_db]) {
            NSLog(@"表单不存在!");
            return nil;
        }
    }
    
    NSMutableArray *data = [[NSMutableArray alloc]init];
    FMResultSet *result = [_db executeQuery:sql];
    while ([result next]) {
        NSString *IDStr = [result stringForColumn:@"ID"];
        NSString *praise = [result stringForColumn:@"praise"];
        NSDictionary *dic = [[NSDictionary alloc]initWithObjectsAndKeys:IDStr,@"ID",praise,@"praise", nil];
        [data addObject:dic];
    }
    
    if (![_db close]) {
        NSLog(@"数据库没有关闭!");
        return nil;
    }
    
    return data;
}
- (BOOL)insertOnShowPraiseTableWithId:(NSString *)idStr withIsPraise:(NSString *)isPraise
{
    NSString *sql = [NSString stringWithFormat:@"insert into '%@'(ID,praise) values('%@','%@')",PRAISE_HISTORY,idStr,isPraise];
    
    if (![_db open]) {
        NSLog(@"数据库没有打开!");
        return NO;
    }
    
    [_db setShouldCacheStatements:YES];
    
    if (![_db tableExists:PRAISE_HISTORY]) {
        if (![self createOnShowPraiseTable:PRAISE_HISTORY byDB:_db]) {
            NSLog(@"表单不存在!");
            return NO;
        }
    }
    
    BOOL isUpdate = [_db executeUpdate:sql];
    
    if (![_db close]) {
        NSLog(@"数据库没有关闭!");
        return NO;
    }
    
    return isUpdate;

}
- (BOOL)upDateOnShowPraiseTableByID:(NSString *)idStr withIsPraise:(NSString *)isPraise
{
    NSString *sql = [NSString stringWithFormat:@"update '%@' set praise = '%@' where ID='%@'",PRAISE_HISTORY,isPraise,idStr];
    if (![_db open]) {
        NSLog(@"数据库没有打开!");
        return NO;
    }
    
    [_db setShouldCacheStatements:YES];
    
    if (![_db tableExists:PRAISE_HISTORY]) {
        if (![self createOnShowPraiseTable:PRAISE_HISTORY byDB:_db]) {
            NSLog(@"表单不存在!");
            return NO;
        }
    }
    
    BOOL isUpdate = [_db executeUpdate:sql];
    
    if (![_db close]) {
        NSLog(@"数据库没有关闭!");
        return NO;
    }
    
    return isUpdate;
}

- (BOOL)deleteByPraiseFileID:(NSString *)name
{
    NSString *sql = [NSString stringWithFormat:@"delete from '%@' where ID='%@'",PRAISE_HISTORY,name];
    if (![_db open]) {
        NSLog(@"数据库没有打开!");
        return NO;
    }
    
    [_db setShouldCacheStatements:YES];
    
    if (![_db tableExists:PRAISE_HISTORY]) {
        if (![self createOnShowPraiseTable:PRAISE_HISTORY byDB:_db]) {
            NSLog(@"表单不存在!");
            return NO;
        }
    }
    
    BOOL isUpdate = [_db executeUpdate:sql];
    
    if (![_db close]) {
        NSLog(@"数据库没有关闭!");
        return NO;
    }
    
    return isUpdate;
}
#pragma mark---亲子秀
#define PRAISE_FORSON (@"Praise_son_table")
- (BOOL)createOnShowPraiseForSonTable:(NSString *)table byDB:(FMDatabase *)db//primary key
{
    //id,文件名，地址，日期
    return [db executeUpdate:[NSString stringWithFormat:@"create table %@(ID text primary key ,praise text)",table]];
}
- (NSArray*)onSelectPraiseForSonCount
{
    NSString *sql = [NSString stringWithFormat:@"select * from '%@'",PRAISE_FORSON];
    
    if (![_db open]) {
        NSLog(@"数据库没有打开!");
        return nil;
    }
    
    [_db setShouldCacheStatements:YES];
    
    if (![_db tableExists:PRAISE_FORSON]) {
        if (![self createOnShowPraiseForSonTable:PRAISE_FORSON byDB:_db]) {
            NSLog(@"表单不存在!");
            return nil;
        }
    }
    
    NSMutableArray *data = [[NSMutableArray alloc]init];
    FMResultSet *result = [_db executeQuery:sql];
    while ([result next]) {
        NSString *IDStr = [result stringForColumn:@"ID"];
        NSString *praise = [result stringForColumn:@"praise"];
        NSDictionary *dic = [[NSDictionary alloc]initWithObjectsAndKeys:IDStr,@"ID",praise,@"praise", nil];
        [data addObject:dic];
    }
    
    if (![_db close]) {
        NSLog(@"数据库没有关闭!");
        return nil;
    }
    
    return data;
}
- (NSArray *)SelectTableByPraiseForSonWithContentID:(NSString *)name
{NSString *sql = [NSString stringWithFormat:@"select * from '%@' where ID='%@'",PRAISE_FORSON,name];
    if (![_db open]) {
        NSLog(@"数据库没有打开!");
        return nil;
    }
    
    [_db setShouldCacheStatements:YES];
    
    if (![_db tableExists:PRAISE_FORSON]) {
        if (![self createOnShowPraiseTable:PRAISE_FORSON byDB:_db]) {
            NSLog(@"表单不存在!");
            return nil;
        }
    }
    
    NSMutableArray *data = [[NSMutableArray alloc]init];
    FMResultSet *result = [_db executeQuery:sql];
    while ([result next]) {
        NSString *IDStr = [result stringForColumn:@"ID"];
        NSString *praise = [result stringForColumn:@"praise"];
        NSDictionary *dic = [[NSDictionary alloc]initWithObjectsAndKeys:IDStr,@"ID",praise,@"praise", nil];
        [data addObject:dic];
    }
    
    if (![_db close]) {
        NSLog(@"数据库没有关闭!");
        return nil;
    }
    
    return data;

    
}
- (BOOL)insertOnShowPraiseForSonTableWithId:(NSString *)idStr withIsPraise:(NSString *)isPraise
{
    NSString *sql = [NSString stringWithFormat:@"insert into '%@'(ID,praise) values('%@','%@')",PRAISE_FORSON,idStr,isPraise];
    
    if (![_db open]) {
        NSLog(@"数据库没有打开!");
        return NO;
    }
    
    [_db setShouldCacheStatements:YES];
    
    if (![_db tableExists:PRAISE_FORSON]) {
        if (![self createOnShowPraiseTable:PRAISE_FORSON byDB:_db]) {
            NSLog(@"表单不存在!");
            return NO;
        }
    }
    
    BOOL isUpdate = [_db executeUpdate:sql];
    
    if (![_db close]) {
        NSLog(@"数据库没有关闭!");
        return NO;
    }
    
    return isUpdate;
    

}
- (BOOL)upDateOnShowPraiseForSonTableByID:(NSString *)idStr withIsPraise:(NSString *)isPraise
{
    NSString *sql = [NSString stringWithFormat:@"update '%@' set praise = '%@' where ID='%@'",PRAISE_FORSON,isPraise,idStr];
    if (![_db open]) {
        NSLog(@"数据库没有打开!");
        return NO;
    }
    
    [_db setShouldCacheStatements:YES];
    
    if (![_db tableExists:PRAISE_FORSON]) {
        if (![self createOnShowPraiseTable:PRAISE_FORSON byDB:_db]) {
            NSLog(@"表单不存在!");
            return NO;
        }
    }
    
    BOOL isUpdate = [_db executeUpdate:sql];
    
    if (![_db close]) {
        NSLog(@"数据库没有关闭!");
        return NO;
    }
    
    return isUpdate;
}
- (BOOL)deleteByPraiseForSonFileID:(NSString *)name
{
    NSString *sql = [NSString stringWithFormat:@"delete from '%@' where ID='%@'",PRAISE_FORSON,name];
    if (![_db open]) {
        NSLog(@"数据库没有打开!");
        return NO;
    }
    
    [_db setShouldCacheStatements:YES];
    
    if (![_db tableExists:PRAISE_FORSON]) {
        if (![self createOnShowPraiseTable:PRAISE_FORSON byDB:_db]) {
            NSLog(@"表单不存在!");
            return NO;
        }
    }
    
    BOOL isUpdate = [_db executeUpdate:sql];
    
    if (![_db close]) {
        NSLog(@"数据库没有关闭!");
        return NO;
    }
    
    return isUpdate;
}

#pragma mark - 最近播放
#define MUSICPLAY_RECENT (@"MusicPlay_recent_table")
- (BOOL)createOnShowMusicPlayForRecentTable:(NSString *)table byDB:(FMDatabase *)db//primary key
{
    //id,文件名，地址，日期,图片背景，日期,感想,标题,userid,个人图片,个人昵称
    return [db executeUpdate:[NSString stringWithFormat:@"create table %@(fileID text primary key ,fileName text,id text,url text,size text,type text,coverPath text,date text,sentiment text,title text,userId text,userPic text,userNick text)",table]];
}
- (NSArray*)onSelectMusicPlayForRecent
{
    NSString *sql = [NSString stringWithFormat:@"select * from '%@'",MUSICPLAY_RECENT];
    
    if (![_db open]) {
        NSLog(@"数据库没有打开!");
        return nil;
    }
    
    [_db setShouldCacheStatements:YES];
    
    if (![_db tableExists:MUSICPLAY_RECENT]) {
        if (![self createOnShowMusicPlayForRecentTable:MUSICPLAY_RECENT byDB:_db]) {
            NSLog(@"表单不存在!");
            return nil;
        }
    }
    
    NSMutableArray *data = [[NSMutableArray alloc]init];
    FMResultSet *result = [_db executeQuery:sql];
    while ([result next]) {
        NSString *idStr = [result stringForColumn:@"id"];
        NSString *fileName = [result stringForColumn:@"fileName"];
        NSString *fileID = [result stringForColumn:@"fileID"];
        NSString *url = [result stringForColumn:@"url"];
        NSString *size = [result stringForColumn:@"size"];
        NSString *type = [result stringForColumn:@"type"];
        NSString *coverPath = [result stringForColumn:@"coverPath"];
        NSString *date = [result stringForColumn:@"date"];
        NSString *sentiment = [result stringForColumn:@"sentiment"];
        NSString *title = [result stringForColumn:@"title"];
        NSString *userId = [result stringForColumn:@"userId"];
        NSString *userPic = [result stringForColumn:@"userPic"];
        NSString *userNick = [result stringForColumn:@"userNick"];
        NSDictionary *dic = [[NSDictionary alloc]initWithObjectsAndKeys:idStr,@"id",fileName,@"fileName",fileID,@"fileID",url,@"url",size,@"size",type,@"type",coverPath,@"coverPath",date,@"date",sentiment,@"sentiment",title,@"title",userId,@"userId",userPic,@"userPic",userNick,@"userNick", nil];
        [data addObject:dic];

    }
    
    if (![_db close]) {
        NSLog(@"数据库没有关闭!");
        return nil;
    }
    
    return data;
}
- (NSArray *)SelectTableByMusicPlayForRecentWithContentID:(NSString *)name
{
    NSString *sql = [NSString stringWithFormat:@"select * from '%@' where fileID='%@'",MUSICPLAY_RECENT,name];
    
    if (![_db open]) {
        NSLog(@"数据库没有打开!");
        return nil;
    }
    
    [_db setShouldCacheStatements:YES];
    
    if (![_db tableExists:MUSICPLAY_RECENT]) {
        if (![self createOnShowMusicPlayForRecentTable:MUSICPLAY_RECENT byDB:_db]) {
            NSLog(@"表单不存在!");
            return nil;
        }
    }
    
    NSMutableArray *data = [[NSMutableArray alloc]init];
    FMResultSet *result = [_db executeQuery:sql];
    while ([result next]) {
        NSString *idStr = [result stringForColumn:@"id"];
        NSString *fileName = [result stringForColumn:@"fileName"];
        NSString *fileID = [result stringForColumn:@"fileID"];
        NSString *url = [result stringForColumn:@"url"];
        NSString *size = [result stringForColumn:@"size"];
        NSString *type = [result stringForColumn:@"type"];
        NSString *coverPath = [result stringForColumn:@"coverPath"];
        NSString *date = [result stringForColumn:@"date"];
        NSString *sentiment = [result stringForColumn:@"sentiment"];
        NSString *title = [result stringForColumn:@"title"];
        NSString *userId = [result stringForColumn:@"userId"];
        NSString *userPic = [result stringForColumn:@"userPic"];
        NSString *userNick = [result stringForColumn:@"userNick"];
        NSDictionary *dic = [[NSDictionary alloc]initWithObjectsAndKeys:idStr,@"id",fileName,@"fileName",fileID,@"fileID",url,@"url",size,@"size",type,@"type",coverPath,@"coverPath",date,@"date",sentiment,@"sentiment",title,@"title",userId,@"userId",userPic,@"userPic",userNick,@"userNick", nil];
        [data addObject:dic];
    }
    
    if (![_db close]) {
        NSLog(@"数据库没有关闭!");
        return nil;
    }
    
    return data;
}
- (BOOL)insertTableMusicPlayForRecentWithId:(NSString *)idStr withFileName:(NSString *)fileName withFileID:(NSString *)fileID withUrl:(NSString *)url withSize:(NSString *)size withType:(NSString *)type
{
    return  [self insertTableMusicPlayForRecentWithId:idStr withFileName:fileName withFileID:fileID withUrl:url withSize:size withType:type withCoverPath:@"" withDate:@"" withSentiment:@"" withTitle:@"" withUserId:@"" withUserPic:@"" withUserNick:@""];
}

- (BOOL)insertTableMusicPlayForRecentWithId:(NSString *)idStr withFileName:(NSString *)fileName withFileID:(NSString *)fileID withUrl:(NSString *)url withSize:(NSString *)size withType:(NSString *)type withCoverPath:(NSString *)coverPath withDate:(NSString *)date withSentiment:(NSString *)sentiment withTitle:(NSString *)title withUserId:(NSString *)userId withUserPic:(NSString *)userPic withUserNick:(NSString *)userNick
{
    NSString *sql = [NSString stringWithFormat:@"insert into '%@'(id,fileName,fileID,url,size,type,coverPath,date,sentiment,title,userId,userPic,userNick) values('%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@')",MUSICPLAY_RECENT,idStr,fileName,fileID,url,size,type,coverPath,date,sentiment,title,userId,userPic,userNick];
    
    if (![_db open]) {
        NSLog(@"数据库没有打开!");
        return NO;
    }
    
    [_db setShouldCacheStatements:YES];
    
    if (![_db tableExists:MUSICPLAY_RECENT]) {
        if (![self createOnShowMusicPlayForRecentTable:MUSICPLAY_RECENT byDB:_db]) {
            NSLog(@"表单不存在!");
            return NO;
        }
    }
    
    BOOL isUpdate = [_db executeUpdate:sql];
    
    if (![_db close]) {
        NSLog(@"数据库没有关闭!");
        return NO;
    }
    
    return isUpdate;

}
- (BOOL)deleteByMusicPlayForRecentFileID:(NSString *)name
{
    NSString *sql = [NSString stringWithFormat:@"delete from '%@' where fileID='%@'",MUSICPLAY_RECENT,name];
    if (![_db open]) {
        NSLog(@"数据库没有打开!");
        return NO;
    }
    
    [_db setShouldCacheStatements:YES];
    
    if (![_db tableExists:MUSICPLAY_RECENT]) {
        if (![self createOnShowMusicPlayForRecentTable:MUSICPLAY_RECENT byDB:_db]) {
            NSLog(@"表单不存在!");
            return NO;
        }
    }
    
    BOOL isUpdate = [_db executeUpdate:sql];
    
    if (![_db close]) {
        NSLog(@"数据库没有关闭!");
        return NO;
    }

    
    return isUpdate;
}
#pragma mark---最近播放(电台)
#define ONLINE_RECENT (@"Online_recent_table")
- (BOOL)createOnShowOnLineForRecentTable:(NSString *)table byDB:(FMDatabase *)db//primary key
{
    //id,文件名，地址，日期
    return [db executeUpdate:[NSString stringWithFormat:@"create table %@(ID text primary key ,MainPicture text,RaduiName text)",table]];
}
- (NSArray*)onSelectRadioAudioPlayForRecent{
    NSString *sql = [NSString stringWithFormat:@"select * from '%@'",ONLINE_RECENT];
    
    if (![_db open]) {
        NSLog(@"数据库没有打开!");
        return nil;
    }
    
    [_db setShouldCacheStatements:YES];
    
    if (![_db tableExists:ONLINE_RECENT]) {
        if (![self createOnShowOnLineForRecentTable:ONLINE_RECENT byDB:_db]) {
            NSLog(@"表单不存在!");
            return nil;
        }
    }
    
    NSMutableArray *data = [[NSMutableArray alloc]init];
    FMResultSet *result = [_db executeQuery:sql];
    while ([result next]) {
        NSString *idStr = [result stringForColumn:@"ID"];
        NSString *RaduiName = [result stringForColumn:@"RaduiName"];
        NSString *MainPicture = [result stringForColumn:@"MainPicture"];
        
        NSDictionary *dic = [[NSDictionary alloc]initWithObjectsAndKeys:idStr,@"ID",RaduiName,@"RaduiName",MainPicture,@"MainPicture", nil];
        [data addObject:dic];
        
    }
    
    if (![_db close]) {
        NSLog(@"数据库没有关闭!");
        return nil;
    }
    
    return data;


}

- (BOOL)insertTableRadioAudioPlayForRecentWithId:(NSString *)idStr withRaduiName:(NSString *)RaduiName withMainPicture:(NSString *)MainPicture {
    NSString *sql = [NSString stringWithFormat:@"insert into '%@'(ID,RaduiName,MainPicture) values('%@','%@','%@')",ONLINE_RECENT,idStr,RaduiName,MainPicture];
    
    if (![_db open]) {
        NSLog(@"数据库没有打开!");
        return NO;
    }
    
    [_db setShouldCacheStatements:YES];
    
    if (![_db tableExists:ONLINE_RECENT]) {
        if (![self createOnShowOnLineForRecentTable:ONLINE_RECENT byDB:_db]) {
            NSLog(@"表单不存在!");
            return NO;
        }
    }
    
    BOOL isUpdate = [_db executeUpdate:sql];
    
    if (![_db close]) {
        NSLog(@"数据库没有关闭!");
        return NO;
    }
    
    return isUpdate;

}
- (BOOL)deleteByRadioAudioPlayForRecentFileID:(NSString *)name{
    NSString *sql = [NSString stringWithFormat:@"delete from '%@' where ID='%@'",ONLINE_RECENT,name];
    if (![_db open]) {
        NSLog(@"数据库没有打开!");
        return NO;
    }
    
    [_db setShouldCacheStatements:YES];
    
    if (![_db tableExists:MUSICPLAY_RECENT]) {
        if (![self createOnShowOnLineForRecentTable:ONLINE_RECENT byDB:_db]) {
            NSLog(@"表单不存在!");
            return NO;
        }
    }
    
    BOOL isUpdate = [_db executeUpdate:sql];
    
    if (![_db close]) {
        NSLog(@"数据库没有关闭!");
        return NO;
    }
    
    
    return isUpdate;
}

#pragma mark - 添加歌曲和亲子秀
#define ADD_LOCAL_PARENT_CHILD_SHOW (@"Add_LocalParentChildShow_table")
- (BOOL)createAddLocalParentChildShowTable:(NSString *)table byDB:(FMDatabase *)db//primary key
{
    //id,标题、发帖人ID、musicid、 感受，类型，图片、日期、mp3，发帖人头像、发帖人昵称、music大小
    return [db executeUpdate:[NSString stringWithFormat:@"create table %@(id text primary key,title text ,userId text,musicId text,content text,type text,picture text,date text,mp3 text,userPic text,userNick text,size text)",table]];
}
- (NSArray *)onSelectAddLocalParentChildShowCount
{
    NSString *sql = [NSString stringWithFormat:@"select * from '%@'",ADD_LOCAL_PARENT_CHILD_SHOW];
    
    if (![_db open]) {
        NSLog(@"数据库没有打开!");
        return nil;
    }
    
    [_db setShouldCacheStatements:YES];
    
    if (![_db tableExists:ADD_LOCAL_PARENT_CHILD_SHOW]) {
        if (![self createAddLocalParentChildShowTable:ADD_LOCAL_PARENT_CHILD_SHOW byDB:_db]) {
            NSLog(@"表单不存在!");
            return nil;
        }
    }
    
    NSMutableArray *data = [[NSMutableArray alloc]init];
    FMResultSet *result = [_db executeQuery:sql];
    while ([result next]) {
        NSString *idStr = [result stringForColumn:@"id"];
        NSString *name = [result stringForColumn:@"title"];
        NSString *userId = [result stringForColumn:@"userId"];
        NSString *musicId = [result stringForColumn:@"musicId"];
        NSString *address = [result stringForColumn:@"content"];
        NSString *type = [result stringForColumn:@"type"];
        NSString *picture = [result stringForColumn:@"picture"];
        NSString *date = [result stringForColumn:@"date"];
        NSString *mp3 = [result stringForColumn:@"mp3"];
        NSString *userPic = [result stringForColumn:@"userPic"];
        NSString *userNick = [result stringForColumn:@"userNick"];
        NSString *size = [result stringForColumn:@"size"];
        NSDictionary *dic = [[NSDictionary alloc]initWithObjectsAndKeys:idStr,@"id",name,@"title",userId,@"userId",musicId,@"musicId",address,@"content",type,@"type",picture,@"picture",date,@"date",mp3,@"mp3",userPic,@"userPic",userNick,@"userNick",size,@"size", nil];
        [data addObject:dic];
    }
    
    if (![_db close]) {
        NSLog(@"数据库没有关闭!");
        return nil;
    }
    
    return data;
}
- (NSArray *)SelectTableByAddLocalParentChildShowWithUserId:(NSString *)date withMusicId:(NSString *)musicId withType:(NSString *)type
{
    NSString *sql = [NSString stringWithFormat:@"select * from '%@' where userId='%@' and musicId='%@' and type='%@'",ADD_LOCAL_PARENT_CHILD_SHOW,date,musicId,type];
    if (![_db open]) {
        NSLog(@"数据库没有打开!");
        return nil;
    }
    
    [_db setShouldCacheStatements:YES];
    
    if (![_db tableExists:ADD_LOCAL_PARENT_CHILD_SHOW]) {
        if (![self createAddLocalParentChildShowTable:ADD_LOCAL_PARENT_CHILD_SHOW byDB:_db]) {
            NSLog(@"表单不存在!");
            return nil;
        }
    }
    
    NSMutableArray *data = [[NSMutableArray alloc]init];
    FMResultSet *result = [_db executeQuery:sql];
    while ([result next]) {
        NSString *idStr = [result stringForColumn:@"id"];
        NSString *name = [result stringForColumn:@"title"];
        NSString *userId = [result stringForColumn:@"userId"];
        NSString *musicId = [result stringForColumn:@"musicId"];
        NSString *address = [result stringForColumn:@"content"];
        NSString *type = [result stringForColumn:@"type"];
        NSString *picture = [result stringForColumn:@"picture"];
        NSString *date = [result stringForColumn:@"date"];
        NSString *mp3 = [result stringForColumn:@"mp3"];
        NSString *userPic = [result stringForColumn:@"userPic"];
        NSString *userNick = [result stringForColumn:@"userNick"];
        NSString *size = [result stringForColumn:@"size"];
        NSDictionary *dic = [[NSDictionary alloc]initWithObjectsAndKeys:idStr,@"id",name,@"title",userId,@"userId",musicId,@"musicId",address,@"content",type,@"type",picture,@"picture",date,@"date",mp3,@"mp3",userPic,@"userPic",userNick,@"userNick",size,@"size", nil];
        [data addObject:dic];
        
    }
    
    if (![_db close]) {
        NSLog(@"数据库没有关闭!");
        return nil;
    }
    
    return data;
}
- (BOOL)insertTableByAddLocalParentChildShowWithId:(NSString *)idStr withTitle:(NSString *)title withUserId:(NSString *)userId withMusicId:(NSString *)musicID withContent:(NSString *)content withType:(NSString *)type withPicture:(NSString *)picture withDate:(NSString *)date withMp3:(NSString *)mp3 withUserPic:(NSString *)userPic withUserNick:(NSString *)nick withSize:(NSString *)size
{
    NSString *sql = [NSString stringWithFormat:@"insert into '%@'(id,title,userId,musicId,content,type,picture,date,mp3,userPic,userNick,size) values('%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@','%@')",ADD_LOCAL_PARENT_CHILD_SHOW,idStr,title,userId,musicID,content,type,picture,date,mp3,userPic,nick,size];
    
    if (![_db open]) {
        NSLog(@"数据库没有打开!");
        return NO;
    }
    
    [_db setShouldCacheStatements:YES];
    
    if (![_db tableExists:ADD_LOCAL_PARENT_CHILD_SHOW]) {
        if (![self createAddLocalParentChildShowTable:ADD_LOCAL_PARENT_CHILD_SHOW byDB:_db]) {
            NSLog(@"表单不存在!");
            return NO;
        }
    }
    
    BOOL isUpdate = [_db executeUpdate:sql];
    
    if (![_db close]) {
        NSLog(@"数据库没有关闭!");
        return NO;
    }
    
    return isUpdate;
}
- (BOOL)deleteByAddLocalParentChildShowFilID:(NSString *)date
{
    NSString *sql = [NSString stringWithFormat:@"delete from '%@' where id='%@'",ADD_LOCAL_PARENT_CHILD_SHOW,date];
    if (![_db open]) {
        NSLog(@"数据库没有打开!");
        return NO;
    }
    
    [_db setShouldCacheStatements:YES];
    
    if (![_db tableExists:ADD_LOCAL_PARENT_CHILD_SHOW]) {
        if (![self createAddLocalParentChildShowTable:ADD_LOCAL_PARENT_CHILD_SHOW byDB:_db]) {
            NSLog(@"表单不存在!");
            return NO;
        }
    }
    
    BOOL isUpdate = [_db executeUpdate:sql];
    
    if (![_db close]) {
        NSLog(@"数据库没有关闭!");
        return NO;
    }
    
    return isUpdate;
}

/*
 create table xx(id integer primary key,phone text)
 insert into xx(id,phone) values(?,?)
 select * from xx where phone = ?
 delete from xx where phone = ?
 update xx set nick = ? where phone=?
 */
@end
